//
//  PickCarsVC.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/6/16.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "PickCarsVC.h"
#import <Masonry.h>
#import "Common.h"
#import "PickCarCell.h"
#import "PickCarsDetailVC.h"
@interface PickCarsVC ()
{
    
    UITableView * table;
    UIView * nav;
    Common * com;

    NSMutableArray * dataSouceArr;
}
@end

@implementation PickCarsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    com = [[Common alloc]init];
    dataSouceArr = [[NSMutableArray alloc]init];
    
    self.view.backgroundColor = WhiteColor;
    
    nav = [self createNav:@"任务"];
    [self.view addSubview:nav];
    [self createTable];
    [self createDate];

}



-(void)createTable{
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 65*kHeight, Main_Width,Main_height-65*kHeight) style:UITableViewStylePlain];
    [table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];
}
-(void)createDate{
    
    int pageNo = 1;
    int pageSize = 10;
    
    NSString * string = nil;

    string = [NSString stringWithFormat:@"%@?pageNo=%d&pageSize=%d",task_Url,pageNo,pageSize];
    
    [Common requestWithUrlString:string contentType:@"application/json" finished:^(id responseObj){
        
        NSLog(@"%@",responseObj);
        
        dataSouceArr = responseObj[@"data"][@"orders"];
        if (dataSouceArr.count>0) {
            [table reloadData];
        }
        
    } failed:^(NSString *errorMsg) {
        NSLog(@"%@",errorMsg);
    }];
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString *str=@"str";
    
    PickCarCell * cell =  [tableView dequeueReusableCellWithIdentifier:str];
    if (cell ==nil) {
        cell = [[PickCarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSLog(@"%ld",indexPath.row);
    
    [cell showInfo:dataSouceArr[indexPath.row]];

    cell.RightBtn.indexpath = indexPath;
    
    [cell.RightBtn addTarget:self action:@selector(pressBtn2:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

-(void)pressBtn2:(NewBtn*)sender{
    
    //departure_Url
    NSString * string = [NSString stringWithFormat:@"%@",departure_Url];
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    
    long row = (long)sender.indexpath.row;
//    [dic setObject:dataSouceArr[row][@"id"] forKey:@"id"];
    PickCarsDetailVC * pickcar = [[PickCarsDetailVC alloc]init];
    pickcar.ID = dataSouceArr[row][@"id"];
    [self.navigationController pushViewController:pickcar animated:YES];
    

//    [com afPostRequestWithUrlString:string parms:dic finishedBlock:^(id responseObj) {
//        NSMutableDictionary * dicObj =[NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"%@",dicObj);
//        NSString * message = [NSString stringWithFormat:@"%@",dicObj[@"message"]];
//        UILabel * label = [com createUIlabel:message andFont:14 andColor:BlackColor];
//        label.frame = CGRectMake(100, 100, 100, 100);
//        [self.view addSubview:label];
//        
//        NSLog(@"%@",message);
//
//    } failedBlock:^(NSString *errorMsg) {
//        
//        
//    }];
//
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return  190*kHeight;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataSouceArr.count;
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
